<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            position: absolute;
            width: 100px;
            height: 100px;
            left: 0;
        }

        .box1 {
            top: 50px;
            background-color: red;
        }

        .box2 {
            top: 200px;
            background-color: pink;
        }
    </style>

    <script src="js/animate4.js"></script>
</head>

<body>
    <button id="btn1">左右移动到600</button>
    <button id="btn2">左右移动到400</button>

    <div class="box1"></div>
    <div class="box2"></div>

    <script>
        // 获取动画元素
        let box1 = document.querySelector('.box1');
        let box2 = document.querySelector('.box2');


        document.getElementById('btn1').onclick = function () {
            // animate(600);

            // 传入要动画的元素
            animate(box1, 600);
        };

        document.getElementById('btn2').onclick = function () {
            // 让box2动画
            animate(box2, 400);
        }
    </script>
</body>

</html>